/*
 * 项   目：spring-boot-demo
 * 作   者：罗毅（ymluo） 
 * 邮   箱：ymluo@iflytek.com
 * 创建时间：2017/11/15 14:32
 */
package com.roin.learn.springboot.demo.mapper;

import com.roin.learn.springboot.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Select("select * from b_user")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "positionId",column = "position_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "userName",column = "user_name"),
            @Result(property = "userPassword",column = "user_password"),
            @Result(property = "userEmail",column = "user_email")
    })
    List<User> getAll();

    @Select("SELECT * FROM b_user WHERE id = #{id}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "positionId",column = "position_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "userName",column = "user_name"),
            @Result(property = "userPassword",column = "user_password"),
            @Result(property = "userEmail",column = "user_email")
    })
    User getOne(int id);
    @Select("SELECT * FROM b_user WHERE user_id = #{userId}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "positionId",column = "position_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "userName",column = "user_name"),
            @Result(property = "userPassword",column = "user_password"),
            @Result(property = "userEmail",column = "user_email")
    })
    User getByUserId(String userId);

    @Insert("INSERT INTO b_user(user_id,user_name,user_password,user_email,position_id,sex) " +
            "VALUES(#{userId},#{userName}, #{userPassword}, #{userEmail},#{positionId},#{sex})")
    void insert(User user);

    @Update("UPDATE b_user SET user_name=#{userName},user_email=#{userEmail},position_id=#{positionId},sex=#{sex} WHERE id =#{id}")
    void update(User user);

    @Delete("DELETE FROM b_user WHERE id =#{id}")
    void delete(int id);

}
